Add remove and list support. Also make all class methods "safe".
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 9 Sep 2005 17:34:40 +0000 (17:34 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 9 Sep 2005 17:34:40 +0000 (17:34 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/python/xen/xend/xenstore/xstransact.py

index 2e03f3498c547b8709d6f11e97de4cf6e37396a9..0b8d8612a1f77d157111e3d692f800f9d8b9f7b2 100644 (file)
@@ -88,40 +88,81 @@ class xstransact:
         else:
             raise TypeError
 
+    def _remove(self, key):
+        path = "%s/%s" % (self.path, key)
+        return xshandle().rm(path)
+
+    def remove(self, *args):
+        if len(args) == 0:
+            raise TypeError
+        for key in args:
+            self._remove(key)
+
+    def _list(self, key):
+        path = "%s/%s" % (self.path, key)
+        return map(lambda x: key + "/" + x, xshandle().ls(path))
+
+    def list(self, *args):
+        if len(args) == 0:
+            raise TypeError
+        ret = []
+        for key in args:
+            ret.extend(self._list(key))
+        return ret
+
+
     def Read(cls, path, *args):
-        t = cls(path)
-        v = t.read(*args)
-        t.commit()
-        return v
+        while True:
+            try:
+                t = cls(path)
+                v = t.read(*args)
+                t.commit()
+                return v
+            except RuntimeError, ex:
+                if ex.args[0] == errno.ETIMEDOUT:
+                    pass
+                raise
 
     Read = classmethod(Read)
 
     def Write(cls, path, *args, **opts):
-        t = cls(path)
-        t.write(*args, **opts)
-        t.commit()
+        while True:
+            try:
+                t = cls(path)
+                t.write(*args, **opts)
+                t.commit()
+                return
+            except RuntimeError, ex:
+                if ex.args[0] == errno.ETIMEDOUT:
+                    pass
+                raise
 
     Write = classmethod(Write)
 
-    def SafeRead(cls, path, *args):
+    def Remove(cls, *args):
         while True:
             try:
-                return cls.Read(path, *args)
+                t = cls(path)
+                t.remove(*args)
+                t.commit()
+                return
             except RuntimeError, ex:
                 if ex.args[0] == errno.ETIMEDOUT:
                     pass
                 raise
 
-    SafeRead = classmethod(SafeRead)
+    Remove = classmethod(Remove)
 
-    def SafeWrite(cls, path, *args, **opts):
+    def List(cls, path, *args):
         while True:
             try:
-                cls.Write(path, *args, **opts)
-                return
+                t = cls(path)
+                v = t.list(*args)
+                t.commit()
+                return v
             except RuntimeError, ex:
                 if ex.args[0] == errno.ETIMEDOUT:
                     pass
                 raise
 
-    SafeWrite = classmethod(SafeWrite)
+    List = classmethod(List)